import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;


// 服务端
public class DataGramPacketDemo04 {
    public static void main(String[] args) throws IOException {
        // 绑定9001
        DatagramSocket datagramSocket = new DatagramSocket(9001);
        byte[] bytes = new byte[1024];
        DatagramPacket datagramPacket = new DatagramPacket(bytes, 0, bytes.length);
        while (true) {
            //接
            datagramSocket.receive(datagramPacket);
            String content = new String(bytes, 0, datagramPacket.getLength());
            System.out.println(content);
            if (content.equals("88")) {
                break;
            }

        }
        if (!datagramSocket.isClosed()) {
            datagramSocket.close();
        }

    }
}
